package com.shuhua.taskServer.controller;

import com.shuhua.common.result.Result;
import com.shuhua.pojo.dto.BankCardDTO;
import com.shuhua.pojo.entity.BankCard;
import com.shuhua.pojo.vo.BankCardVO;
import com.shuhua.taskServer.service.BankCardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/bankcard")
public class BankCardController {
    @Autowired
    BankCardService bankCardService;

    @GetMapping("/list")
    public List<BankCardVO> list(@RequestParam("craftsmanId") Integer craftsmanId) {
        try {
            return bankCardService.getCardsByUserId(craftsmanId);
        } catch (Exception e) {
            e.printStackTrace();  // 打印异常堆栈
            throw e;  // 或者返回一个错误信息
        }
    }

    @PostMapping("/add")
    public Result add(@RequestBody BankCardDTO bankCardDTO ) {
      try  {
        return bankCardService.addBankCard(bankCardDTO);
      } catch (Exception e) {
        e.printStackTrace();  // 打印异常堆栈
        throw e;  // 或者返回一个错误信息
      }
    }

    @GetMapping("/detailinfo")
    public Result getDetail(@RequestBody BankCardDTO bankCardDTO) {
      try {
        return bankCardService.getdetail(bankCardDTO);
      } catch (Exception e) {
        e.printStackTrace();  // 打印异常堆栈
        throw e;  // 或者返回一个错误信息
      }
    }


    @DeleteMapping("/delete")
    public Result delete(@RequestBody BankCardDTO bankCardDTO) {
        try{
        return bankCardService.delete(bankCardDTO);
   }catch(Exception e){
            e.printStackTrace();
            throw e;
        }

    }


}
